package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Banner;
import cn.wolfcode.wolf2w.domain.Strategy;
import cn.wolfcode.wolf2w.domain.Travel;
import cn.wolfcode.wolf2w.query.BannerQuery;
import cn.wolfcode.wolf2w.service.IBannerService;
import cn.wolfcode.wolf2w.service.IStrategyService;
import cn.wolfcode.wolf2w.service.ITravelService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;


@Controller
@RequestMapping("banner")
public class BannerController {
    @Autowired
    private IBannerService bannerService;
    @Autowired
    private ITravelService travelService;
    @Autowired
    private IStrategyService strategyService;

    @RequestMapping("/list")
    public String banner(Model model, @ModelAttribute("qo") BannerQuery qo){
        Page<Banner> query = bannerService.query(qo);
        model.addAttribute("page",query);
        return "banner/list";
    }
    @RequestMapping("/getAllType")
    @ResponseBody
    public Object getAllType(){
        HashMap<String, Object> map = new HashMap<>();
        List<Strategy> strategies = strategyService.listAll();
        List<Travel> travels = travelService.listAll();
        map.put("sts",strategies);
        map.put("ts",travels);
        return JsonResult.success(map);
    }
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Banner banner){
        bannerService.saveOrUpdate(banner);
        return JsonResult.success();
    }


}
